package arsmodeller.commands;

import org.eclipse.gef.commands.Command;

import arsmodeller.figure.ThingFigure;
import arsmodeller.model.Link;
import arsmodeller.model.ObjectProcessingDiagram;
import arsmodeller.model.Thing;

public class LinkCreateCommand extends Command {
	private Thing source;
	private Thing target;
	private Link link;
	private ObjectProcessingDiagram opd;

	@Override
	public boolean canExecute() {
		return source != null && target != null && link != null;
	}

	@Override
	public void execute() {
		link.setSource(source);
		link.setTarget(target);
		link.setOpd(opd);
	}

	@Override
	public void undo() {
		link.getSource().getOutgoingLinks().remove(link);
		link.setSource(null);
		link.getTarget().getIncomingLinks().remove(link);
		link.setTarget(null);
		link.setOpd(null);
	}

	public void setTarget(Thing target) {
		this.target = target;
	}

	public void setSource(Thing source) {
		this.source = source;
	}

	public void setLink(Link link) {
		this.link = link;
	}

	public void setOPD(ObjectProcessingDiagram opd) {
		this.opd = opd;
	}

}
